package com.turing.usdtpay.mvp.presenter;

import android.app.Activity;

import com.google.gson.Gson;
import com.turing.usdtpay.entity.TeamData;
import com.turing.usdtpay.http.ApiService;
import com.turing.usdtpay.http.ApiUrl;
import com.turing.usdtpay.http.callback.ApiCallback;
import com.turing.usdtpay.http.entity.ResponseDate;
import com.turing.usdtpay.mvp.contract.TeamContract;

import java.util.HashMap;

/**
 * @作者：JAY
 * @创建时间：2019/11/5 16:53
 * @描述：
 **/
public class TeamPresenter implements TeamContract.Present {
    private TeamContract.View mView;

    public TeamPresenter(TeamContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void getTeamInfo(Activity activity) {
        ApiService.getInstance().postRequestWithCommmon(activity, ApiUrl.API_TEAM_INFO, new HashMap<String, String>(), new ApiCallback() {
            @Override
            public void onSuccess(int code, ResponseDate date) {
                if (date.getRet() == 1){
                    Gson gson = new Gson();
                    TeamData data = gson.fromJson(date.getDate(), TeamData.class);
                    mView.getSuccess(data);
                }else {
                    mView.onFail(date.getMsg());
                }
            }

            @Override
            public void onFailure(Throwable exception) {
                mView.onFail(exception.getMessage());
            }
        });
    }
}
